<template>
  <div id="wechat-login-box" style="display: none">
    <el-divider><span class="title">微信登录</span></el-divider>
    <div id="button-box">
      <div id="wechat-login-button" @click="loginByWechat"></div>
    </div>
  </div>
</template>

<script>
import WechatLoginTools from '../tools/WechatLoginTools'

export default {
  name: 'ThirdUserLoginBox',
  methods:{
    // 根据微信用户绑定登陆
    loginByWechat:function () {
      if (localStorage.getItem("MyPrivacyAgreement")!=='1'){
        return this.$message.warning('请先勾选同意《可可商城用户隐私协议》')
      }
      let $this=this
      WechatLoginTools.getCode(function (ret) {
        var jsonData=JSON.stringify(ret)
        $this.isLoading = true
        $this.MyRequest($this.ApiDoNameShop+'Public/loginByThirdUser',{data:jsonData},function (data) {
          if (data && data.token){
            // 微信用户已经绑定
            $this.isLoading = false
            $this.CurrUser.setCache({
              token: data.token,
              username: data.username,
            })
            // $this.bus.$emit('UserLoginCallBus')
            $this.$router.push("/")
          }else{
            // 微信用户未绑定
            localStorage.setItem("thirdUser",JSON.stringify(ret))
            $this.$router.push("/WechatBinding")
          }
        })
      });
    },
  }
}
</script>

<style scoped>

</style>
